
package com.ami.vmedia;

import com.ami.iusb.CDROMRedir;
import com.ami.iusb.FloppyRedir;
import com.ami.iusb.HarddiskRedir;
import com.ami.iusb.IUSBRedirSession;
import com.ami.kvm.jviewer.Debug;
import com.ami.kvm.jviewer.JViewer;
import com.ami.vmedia.gui.DeviceControlPanel;
import com.ami.vmedia.gui.DevicePanel;
import com.ami.vmedia.gui.VMPane;

public class RedirectionStatusMonitor extends Thread {
	private boolean cdRedirected = false;
	private boolean fdRedirected = false;
	private boolean hdRedirected = false;
	private IUSBRedirSession iusbRedirSession = null;
	private boolean run = false;

	public RedirectionStatusMonitor() {
		this.iusbRedirSession = VMApp.getInstance().getIUSBRedirSession();
		this.run = true;
		start();
	}

	public void run() {
		DevicePanel localDevicePanel = null;
		while (this.run) {
			try {
				Thread.sleep(1L);
			} catch (InterruptedException localInterruptedException) {
				Debug.out.println(localInterruptedException);
			}

			if (this.iusbRedirSession != null) {
				try {
					int i = 0;
					int j = 0;
					int k = 0;

					i = VMApp.getInstance().getNumCD();
					j = VMApp.getInstance().getNumFD();
					k = VMApp.getInstance().getNumHD();
					this.cdRedirected = false;
					this.fdRedirected = false;
					this.hdRedirected = false;
					for (int m = 0; m < i; m++) {
						try {
							if (this.iusbRedirSession.getCdromSession(m) != null) {
								localDevicePanel = VMApp.getVMPane().getDeviceControlPanel(0, m).getDevicePanel();

								if (this.iusbRedirSession.getCdromSession(m).isCdRedirectionKilled()) {
									this.iusbRedirSession.getCdromSession(m).setCdRedirectionKilled(false);
									this.iusbRedirSession.StopCDROMRedir(m, 2);
									if (!localDevicePanel.isImageSelected()) {
										VMApp.getVMPane().physicalDriveChangeState(0, m,
												localDevicePanel.getSelectedDeviceString(), true);
									}
									VMApp.getVMPane().getDeviceControlPanel(0, m).updateDeviceControlPanel();

								} else if (this.iusbRedirSession.getCdromSession(m).isCdImageEjected()) {
									if (this.iusbRedirSession.getCdromSession(m).isCdImageRedirected()) {
										this.iusbRedirSession.StopISORedir(m, 1);
									} else {
										this.iusbRedirSession.StopCDROMRedir(m, 1);
									}
									if (!localDevicePanel.isImageSelected()) {
										VMApp.getVMPane().physicalDriveChangeState(0, m,
												localDevicePanel.getSelectedDeviceString(), true);
									}
									VMApp.getVMPane().getDeviceControlPanel(0, m).updateDeviceControlPanel();

								} else if (this.iusbRedirSession.getCdromSession(m).isCdServiceRestarted()) {
									if (this.iusbRedirSession.getCdromSession(m).isCdImageRedirected()) {
										this.iusbRedirSession.StopISORedir(m, 4);
									} else {
										this.iusbRedirSession.StopCDROMRedir(m, 4);
									}
									if (!localDevicePanel.isImageSelected()) {
										VMApp.getVMPane().physicalDriveChangeState(0, m,
												localDevicePanel.getSelectedDeviceString(), true);
									}
									VMApp.getVMPane().getDeviceControlPanel(0, m).updateDeviceControlPanel();
								} else {
									this.cdRedirected = true;
								}
							}
						} catch (Exception localException2) {
							Debug.out.println(localException2);
							VMApp.getVMPane().getDeviceControlPanel(0, m).updateDeviceControlPanel();
						}
					}
					if ((!JViewer.isVMApp()) && (!this.cdRedirected)) {
						this.iusbRedirSession.updateCDToolbarButtonStatus(this.cdRedirected);
					}
					for (int m = 0; m < j; m++) {
						try {
							if (this.iusbRedirSession.getFloppySession(m) != null) {
								localDevicePanel = VMApp.getVMPane().getDeviceControlPanel(1, m).getDevicePanel();
								if (this.iusbRedirSession.getFloppySession(m).isFdRedirectionKilled()) {
									this.iusbRedirSession.getFloppySession(m).setFdRedirectionKilled(false);
									this.iusbRedirSession.StopFloppyRedir(m, 2);
									if (!localDevicePanel.isImageSelected()) {
										VMApp.getVMPane().physicalDriveChangeState(1, m,
												localDevicePanel.getSelectedDeviceString(), true);
									}
									VMApp.getVMPane().getDeviceControlPanel(1, m).updateDeviceControlPanel();

								} else if (this.iusbRedirSession.getFloppySession(m).isFdImageEjected()) {
									if (this.iusbRedirSession.getFloppySession(m).isFdImageRedirected()) {
										this.iusbRedirSession.StopFloppyImageRedir(m, 1);
									} else {
										this.iusbRedirSession.StopFloppyRedir(m, 1);
									}
									if (!localDevicePanel.isImageSelected()) {
										VMApp.getVMPane().physicalDriveChangeState(1, m,
												localDevicePanel.getSelectedDeviceString(), true);
									}
									VMApp.getVMPane().getDeviceControlPanel(1, m).updateDeviceControlPanel();

								} else if (this.iusbRedirSession.getFloppySession(m).isFdServiceRestarted()) {
									if (this.iusbRedirSession.getFloppySession(m).isFdImageRedirected()) {
										this.iusbRedirSession.StopFloppyImageRedir(m, 4);
									} else {
										this.iusbRedirSession.StopFloppyRedir(m, 4);
									}
									if (!localDevicePanel.isImageSelected()) {
										VMApp.getVMPane().physicalDriveChangeState(1, m,
												localDevicePanel.getSelectedDeviceString(), true);
									}
									VMApp.getVMPane().getDeviceControlPanel(1, m).updateDeviceControlPanel();
								} else {
									this.fdRedirected = true;
								}
							}
						} catch (Exception localException3) {
							Debug.out.println(localException3);
							VMApp.getVMPane().getDeviceControlPanel(1, m).updateDeviceControlPanel();
						}
					}
					if ((!JViewer.isVMApp()) && (!this.fdRedirected)) {
						this.iusbRedirSession.updateFDToolbarButtonStatus(this.fdRedirected);
					}
					for (int m = 0; m < k; m++) {
						try {
							if (this.iusbRedirSession.getHarddiskSession(m) != null) {
								localDevicePanel = VMApp.getVMPane().getDeviceControlPanel(2, m).getDevicePanel();
								if (this.iusbRedirSession.getHarddiskSession(m).isHdRedirectionKilled()) {
									this.iusbRedirSession.getHarddiskSession(m).setHdRedirectionKilled(false);
									this.iusbRedirSession.StopHarddiskImageRedir(m, 2);
									if (!localDevicePanel.isImageSelected()) {
										VMApp.getVMPane().physicalDriveChangeState(2, m,
												localDevicePanel.getSelectedDeviceString(), true);
									}
									VMApp.getVMPane().getDeviceControlPanel(2, m).updateDeviceControlPanel();

								} else if (this.iusbRedirSession.getHarddiskSession(m).isHdImageEjected()) {
									if (this.iusbRedirSession.getHarddiskSession(m).isHdImageRedirected()) {
										this.iusbRedirSession.StopHarddiskImageRedir(m, 1);
									} else {
										this.iusbRedirSession.StopHarddiskRedir(m, 1);
									}
									if (!localDevicePanel.isImageSelected()) {
										VMApp.getVMPane().physicalDriveChangeState(2, m,
												localDevicePanel.getSelectedDeviceString(), true);
									}
									VMApp.getVMPane().getDeviceControlPanel(2, m).updateDeviceControlPanel();

								} else if (this.iusbRedirSession.getHarddiskSession(m).isHdServiceRestarted()) {
									if (this.iusbRedirSession.getHarddiskSession(m).isHdImageRedirected()) {
										this.iusbRedirSession.StopHarddiskImageRedir(m, 4);
									} else {
										this.iusbRedirSession.StopHarddiskRedir(m, 4);
									}
									if (!localDevicePanel.isImageSelected()) {
										VMApp.getVMPane().physicalDriveChangeState(2, m,
												localDevicePanel.getSelectedDeviceString(), true);
									}
									VMApp.getVMPane().getDeviceControlPanel(2, m).updateDeviceControlPanel();
								} else {
									this.hdRedirected = true;
								}
							}
						} catch (Exception localException4) {
							Debug.out.println(localException4);
							VMApp.getVMPane().getDeviceControlPanel(2, m).updateDeviceControlPanel();
						}
					}
					if ((!JViewer.isVMApp()) && (!this.hdRedirected))
						this.iusbRedirSession.updateHDToolbarButtonStatus(this.hdRedirected);
				} catch (Exception localException1) {
					Debug.out.println(localException1);
				}
			}
		}
	}

	public void stopRedirectionStatusMonitior() {
		this.run = false;
	}
}

/*
 * Location: D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\vmedia\
 * RedirectionStatusMonitor.class Java compiler version: 5 (49.0) JD-Core
 * Version: 0.7.1
 */